import { Suspense, lazy, useEffect, useState } from "react";
import AppRouter from "../router";
const AimLogin = lazy(() => import("aim-library").then((module) => ({ default: module.AimLogin })));
function App() {
    const [loginVisible, setLoginVisible] = useState(false);

    useEffect(() => {
        if (loginVisible) {
            _refreshListener();
        }
    }, [loginVisible]);
    const _refreshListener = async () => {
        const { refreshListener } = await import("aim-library");
        refreshListener();
    };
    const showModal = () => {
        setLoginVisible(true);
    };
    const handleCancel = () => {
        setLoginVisible(false);
    };
    const handleOk = () => {
        setLoginVisible(false);
    };
    return (
        <div>
            <button onClick={() => showModal()}>login</button>
            <Suspense fallback={<div>Loading...</div>}>
                {loginVisible && (
                    <AimLogin
                        visible={loginVisible}
                        type="login"
                        onCancel={handleCancel}
                        onOk={handleOk}
                    />
                )}
            </Suspense>
            <AppRouter />
        </div>
    );
}

export default App;
